package com.nervenets.web.controller;

import com.nervenets.utils.JodaUtils;
import org.weixin4j.Weixin;
import org.weixin4j.WeixinException;

import java.util.Hashtable;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by joe on 17-3-16.
 */
@SuppressWarnings("ALL")
public final class Global {
    private static final String COUNT_PREFIX = "_COUNT_UID_";
    private static final String SUM_PREFIX = "_SUM_UID_";
    private static final String BEACON_COUNT_PREFIX = "_COUNT_BID_";
    /**
     * 全局摇奖次数计数
     */
    public static AtomicLong numberCounter = new AtomicLong(0);
    /**
     * 普通缓存数据，key-value
     */
    public static Hashtable userData = new Hashtable();
    /**
     * 全局微信工具类实例
     */
    private static Weixin weixin;

    /**
     * 商家红包奖励
     */
    public static Hashtable<Integer, String> storeRedPacketAllotData = new Hashtable();

    public static Weixin getWeixin() throws WeixinException {
        if (null == weixin) weixin = new Weixin(false);
        return weixin;
    }

    public static final String getAesKey() {
        return "Luckys1535960331";
    }

    public static final String getAesIv() {
        return "charms1535960331";
    }

    /**
     * Created by Joe on 2018/1/3.
     */
    public static final class Constants {
        public static final String SESSION_USER_ID = "SESSION_USER_ID";
        public static final String SESSION_USER_ROLE = "SESSION_USER_ROLE";
        public static final String SESSION_RP = "SESSION_RP_%s";
        public static final String SESSION_RP_LOCK = "SESSION_RP_LOCK";
        public static final String REDIS_OBJECT_LOCK = "REDIS_OBJECT_LOCK_%s";
        public static final String REDIS_USER_WEALTH_LOCK = "REDIS_USER_WEALTH_LOCK_%s";
        public static final String TAGS_KEY = "TAGS_KEY";
        public static final String MOBILE_VALIDATION_CODE = "MOBILE_VALIDATION_CODE_%s";
    }

    public static final class OrderNumber {
        public static final String MB = "MB";
        public static final String VIP = "VP";
        public static final String TRANSFERS = "TR";
        public static final String RECHARGE = "RC";

        public static String getMB(long orderId) {
            return MB + JodaUtils.getTimestamp() + "" + orderId;
        }

        public static String getMBCreateNumber(int createTime, long orderId) {
            return MB + createTime + "" + orderId;
        }

        public static String getVip(long orderId) {
            return VIP + JodaUtils.getTimestamp() + "" + orderId;
        }

        public static String getTransfers(long unionId) {
            return TRANSFERS + JodaUtils.getTimestamp() + "" + unionId;
        }

        public static String getRecharge(long unionId) {
            return RECHARGE + JodaUtils.getTimestamp() + "" + unionId;
        }
    }

    public static final class Config {
        public static final String APP_PRIVATE_KEY = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDGf9nGh531xhleid1nY8UGt2R4nsfpy3SI+qDrk5UW3bJeO0ObpUu3LpFSn6zTZzI2WdVAHHPbWofmh09sFA3p0vxgUXSpUX4Nnop+AYOv5PJAk8L7pAnSFtxixrOyulTNJXIEGa6FEuNcaGW3/da1bm3+kiZ4YCmtqesIOT/6Ttvm0ciHMYRdfcPp405rIo7eMLAuaPq24XFpsf6YDw0PRI92dLK8isjYAEtlH6fJ6TR156f+SOYQnkcpBIL9e4CjoD3CTv3cpmI8L/GlkRXPy53XJiDOGOQrkD5P5G31N5cmKyM2a5w2aUfPhl0YtiFbx9Mzem6qFftllkmBfFZ3AgMBAAECggEAIrddmTFC2SdKbJRkGp8CaIhOlCIBCMzClupuloT7QEKJ3Z0z19bzBRip5e9zRI355DOV7l6LjMOqnRDxPQ/M1yZFaXsVkj9kcnFV+2+8XlkGXXD6WxR3ezzwUn46E3ovNqnj5P+w3ClPhmvjzmgg0x57MljRTaBT6cGcD5YjsF0ngbmWjM9xMxakRs3C7feiOm9wzMXpqEJcyb1pNrQKdrls6n/c6ssbSDkySGMWjIe7eFRCrBfcMhVHrMxaw9OQs+U0lxaQLPqChOY53kriAsP8xtTAjimtnNK3rcpL+Qd/nf5U/JVQETZ/lgUKJqZ4av0Xq0C8jgstUq04/LTWsQKBgQDq1YY57eLSTHV5/8yYxo+hx2Gufo03Pvs0Mpnfjo304gdWzcMc5eDKEjZQUZxrgiANraqHhqEYJg+vE7cFH5GZwPoUfpwUc/KKQnurq6PUO0dkbUz4oouJvIeLHjuobblNl7tQ67CSqc8jK8Spc3THclGJQGDe3O9+8sYb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OqvbxOj+XMtTA81G5PbR6d0MahfE6dFm1wv8YMwIDAQAB";
        public static final String APP_ID = "2018112762336975";
    }
}
